<template>
    <div class="order-list-items fix-order-listing">
        <normal-order-list v-for="(item, index) in $route.params.items" :key="index"
            :ibase="item.base" :dataset="item.items" :index="index" mode="unbutton" class="el-item"
        />
        <div class="page-bottom-bar">
            <div class="flex-item tip-message">预估报价：<span>￥</span><span>{{ orderPrice }}</span></div>
            <div class="flex-item">
                <span @click="eventClickSubmitHandin" class="bar-button bar-button-green">确认上交</span>
            </div>
        </div>
    </div>
</template>

<script>
    import { List, Dialog } from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-salesman.vue';

    export default {
        name: 'SalesmanOrderHandInConfirm',
        components:{
            [List.name]: List,
            NormalOrderList
        },
        data() {
            return {
                orderPrice: 0
            }
        },
        mounted() {
            if(!this.$route.params.items) this.$router.push('/salesman/order-listing?index=0');

            var amount = 0;
            for(let x of this.$route.params.items) {
                amount += parseFloat(x.base.amount);
            }
            this.orderPrice = amount.toFixed(2);
        },
        methods: {
            buildConfirmOrderDataset() {
                var result = [];
                for(let x of this.$route.params.items) {
                    result.push({
                        id: x.base.id
                    });
                }
                return result;
            },
            eventClickSubmitHandin() {
                var url = '/api/home/order/shopadd',
                    param = {
                        garbagelist: JSON.stringify(this.buildConfirmOrderDataset()),
                        token: this.$store.state.options.user.token
                    };

                this.$util.postRequestInterface(url,param,(res)=>{
                    Dialog.alert({
                        title:'提示',
                        message: '订单已提交'
                    }).then(() => {
                        this.$router.push({
                            path: '/salesman/order-listing', query: {
                                index: 0
                            }
                        });
                    });
                });
            }
        }
    }
</script>

<style lang='scss' scoped>
    @import "../../libs/styles/bottom-fixed-bar.scss";

    .order-list-items {

        .el-item {
            padding: 0.5rem 1rem 1.6rem;
        }
    }

    .tip-message {
        padding-left: 1rem;
        box-sizing: border-box;

        span {
            color: #FF0000;
        }

        span:first-child {
            font-size: 1.3rem;
        }

        span:last-child {
            font-size: 1.9rem;
        }
    }
</style>
